/**
 * @author banglong
 * @date 2016/1/4
 */
define(['avalon', 'jquery', 'printApi', 'tools',
  "text!../html/printTemplate/ly.html!strip"
], function (avalon, $, api, tools, htmlTemplate) {
  return function () {
    var runtimeParam;
    var getRuntimeParam = function () {
      return {
        timeObj: {}
      };
    };

    var vm;
    var getVmOption = function () {
      return {
        $id: 'ly',
        header: ''
      }
    };

    function getGoodsBookInfo(goodsBookID) {
      api.getGoodsBookInfo({
        className: 'GoodsBookManager',
        method: 'GetGoodsBookByID',
        goodsBookID: goodsBookID
      }).then(function (jsonResult) {

        if (jsonResult.issuccess !== 0) {
          Promise.reject('获取账册信息失败');
        }

        var result = JSON.parse(jsonResult.result);
        runtimeParam.GoodsBookInfo = result;
        vm.header = result.GoodsBookName + '领用单';

      })['catch'](function (ex) {
        tools.alterError(ex)
      });
    }

    this.init = function (param) {
      runtimeParam = Object.assign({}, param);
      avalon.vmodels['root'].currPath = htmlTemplate;
      vm = avalon.define(getVmOption());
      avalon.scan(document.body);
      // 获取账册信息
      getGoodsBookInfo(runtimeParam.GoodsBookID)
    }
  }
});